package com.yc.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.domain.Book;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @author yc
 * @create 2022-01-23 15:20
 */
@SpringBootTest
public class BookMapperTestCase {

    @Autowired
    private BaseMapper<Book> bookBaseMapper;

    @Test
    void testGetById() {
        Book book = bookBaseMapper.selectById(1);
        System.out.println(book);
    }

    @Test
    void testInsert() {
        Book book = new Book();
        book.setDescription("好书");
        book.setName("无字天书");
        book.setType("天书");
        bookBaseMapper.insert(book);
    }

    @Test
    void page() {
        IPage page = new Page(2, 5);
        bookBaseMapper.selectPage(page, null);
    }

    @Test
    void testCondition() {
//        QueryWrapper<Book> queryWrapper = new QueryWrapper<>();
//        queryWrapper.like("name", "spring");

        LambdaQueryWrapper<Book> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.like(Book::getName, "c");
        String name = null;
        queryWrapper.like(name != null, Book::getName, name);

        bookBaseMapper.selectList(queryWrapper);
    }
}
